package controller

import (
	"context"
	"lot_admin_api/api"
	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var Role = cRole{}

type cRole struct{}

// AddRole  添加角色
func (h *cRole) AddRole(ctx context.Context, req *api.AddRoleReq) (res *model.RoleIdRes, err error) {
	// 获取解析token得到用户信息
	Id, err := service.Role().AddRoleReq(ctx, req)
	res = &model.RoleIdRes{
		Id: Id,
	}
	return res, err
}

// EditRole  编辑角色
func (h *cRole) EditRole(ctx context.Context, req *api.EditRoleReq) (res *model.RoleIdRes, err error) {
	// 获取解析token得到用户信息
	Id, err := service.Role().EditRole(ctx, req)
	res = &model.RoleIdRes{
		Id: Id,
	}
	return res, err
}

// RoleInfo  获取角色详情及权限
func (h *cRole) RoleInfo(ctx context.Context, req *api.RoleInfoReq) (res *model.RoleDetailsInfoRes, err error) {
	res, err = service.Role().RoleInfo(ctx, req)
	return res, err
}

// RoleListInfo  获取角色列表
func (h *cRole) RoleListInfo(ctx context.Context, req *api.RoleListInfoReq) (res *model.RoleListPageRes, err error) {
	res, err = service.Role().RoleListInfoReq(ctx, req.RoleTerm)
	return res, err
}

// DeleteRole  删除角色
func (h *cRole) DeleteRole(ctx context.Context, req *api.DeleteRoleReq) (res *model.RoleIdRes, err error) {
	Id, err := service.Role().DeleteRole(ctx, req)
	res = &model.RoleIdRes{
		Id: Id,
	}
	return res, err
}
